package com.longcai.piaojia.activity;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longcai.piaojia.BaseApplication;
import com.longcai.piaojia.R;
import com.umeng.analytics.MobclickAgent;
import com.umeng.analytics.game.UMGameAgent;
import com.zcx.helper.activity.AppV4PictureActivity;
import com.zcx.helper.util.UtilSDCard;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2016/3/14.
 */
public abstract class BasePictureActivity extends AppV4PictureActivity {

    private static String[] PERMISSIONS_STORAGE = {
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Check if we have write permission
        int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (permission != PackageManager.PERMISSION_GRANTED) {
            // We don't have permission so prompt the user
            ActivityCompat.requestPermissions(
                    this,
                    PERMISSIONS_STORAGE,
                    1
            );
        }

    }

    public void setBackTrue() {

        try {

            findViewById(R.id.title_back_rl).setVisibility(View.VISIBLE);
            findViewById(R.id.title_back_rl).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setTitleName(String name) {

        try {

            findViewById(R.id.title_name_ll).setVisibility(View.VISIBLE);
            if (name.length() > 10) {

                name = name.substring(0, 10) + "...";

            }
            ((TextView) findViewById(R.id.title_name_tv)).setText(name);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    @Override
    protected String getCameraAbsolutePath() {

        return UtilSDCard.getSDCardPath() + "piaojia/";

    }

    @Override
    protected void onResume() {
        super.onResume();

        JPushInterface.onResume(this);

        // 集成基本统计分析,初始化 Session
        MobclickAgent.onResume(this);

    }

    @Override
    protected void onPause() {
        super.onPause();

        JPushInterface.onPause(this);

        // //集成基本统计分析, 结束 Session
        MobclickAgent.onPause(this);

    }

}
